<?php

class Library_BooksController extends Zend_Controller_Action
{

    public function init()
    {
       $contextSwitch = $this->_helper->getHelper('contextSwitch');
       		$contextSwitch->addActionContext('list', 'json')
       						->initContext();
    }

    public function indexAction()
    {
        // action body
    }

    public function listAction()
    {
    	$bookMapper = Library_Model_BookMapper::getInstance();
    	/* $book = $bookMapper->searchById(4);
    	$books = $bookMapper->getAllBooks(); */
    	$books = $bookMapper->getBooksAtPage($this->_getParam('page', 1));
    	
    	$this->view->books = $books;
    	Zend_Registry::get('logger')->info($books);
    	if(!$this->_request->isXmlHttpRequest()){
    		$this->view->paginator = $bookMapper->getPaginator();
    	} else{
    		$this->view->currentPage = $bookMapper->getPaginator()->getCurrentPageNumber();
    	}
    	
    	
    	
    	
    	//$this->view->books = $books;
    	
        /* $bookList = new Library_Model_ListBooks();
        $books = $bookList->listBooks($this->_getParam('page', 1));
                
        $this->view->books = $books;
        if(!$this->_request->isXmlHttpRequest()){
        	$this->view->paginator = $bookList->getPaginator();
        } else{
        	$this->view->currentPage = $bookList->getPaginator()->getCurrentPageNumber();
        }
        	
        
        $number = 1345.67;
        $this->view->number = Zend_Locale_Format::toNumber($number,
        							array('precision' => 2, 'locale' => Zend_Registry::get('locale'))); */
    }
}



